package com.ymatou.iapi.dguser.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.CreateUserBackBean;
import com.ymatou.iapi.dguser.parameter.GetSellerInfoByMobileBean;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.dguser.service.GetSellerInfoByMobileCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.utils.TestDataManager;
/**
*根据手机号码查询商家信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetSellerInfoByMobile{
	private static GetSellerInfoByMobileBean getsellerinfobymobileBean;
	private static GetSellerInfoByMobileCall getsellerinfobymobileCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据手机号码查询商家信息");
	}

	@Before
	public void caseUp() {
		getsellerinfobymobileBean=new GetSellerInfoByMobileBean();
		getsellerinfobymobileCall=new GetSellerInfoByMobileCall();
	}
 
	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getsellerinfobymobileCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSellerInfoByMobile_001() {
		Logger.start(true,"根据手机号码查询商家信息成功");
		try {
			UserCreateBean u = DGUserCallService.initSellerUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			getsellerinfobymobileBean.setMobile(u.getMobile());
			getsellerinfobymobileBean.setMobileAreaCode(u.getMobileAreaCode());
			getsellerinfobymobileCall.setData(getsellerinfobymobileBean);
			getsellerinfobymobileCall.callService();			
			Logger.verifyEquals("true", getsellerinfobymobileCall.getString("success"), "验证success");
			Logger.verifyEquals(user, getsellerinfobymobileCall.getJsonObject().get("sellerDto").getAsJsonObject().get("userId").getAsInt(), "验证userId");
			//userStauts 0 正常
			Logger.verifyEquals(0, getsellerinfobymobileCall.getJsonObject().get("sellerDto").getAsJsonObject().get("userStauts").getAsInt(), "验证userStauts");
			Logger.verifyEquals(true, getsellerinfobymobileCall.getJsonObject().get("bindWx").getAsBoolean(), "验证bindWx");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetSellerInfoByMobile_002() {
		Logger.start(true,"手机号和区号不匹配没有查到数据");
		try {
			UserCreateBean u = DGUserCallService.initSellerUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			getsellerinfobymobileBean.setMobile(u.getMobile());
			getsellerinfobymobileBean.setMobileAreaCode(u.getMobileAreaCode()+1);
			getsellerinfobymobileCall.setData(getsellerinfobymobileBean);
			getsellerinfobymobileCall.callService();			
			Logger.verifyEquals("true", getsellerinfobymobileCall.getString("success"), "验证success");
			Logger.verifyIsNull(getsellerinfobymobileCall.getJsonObject().get("sellerDto"), "验证没数据");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetSellerInfoByMobile_003() {
		Logger.start(true,"不输入手机号失败");
		try {
//			getsellerinfobymobileBean.setMobile(TestDataManager.getPhoneNum());
			getsellerinfobymobileBean.setMobileAreaCode("1");
			getsellerinfobymobileCall.setData(getsellerinfobymobileBean);
			getsellerinfobymobileCall.callService();			
			Logger.verifyEquals("false", getsellerinfobymobileCall.getString("success"), "验证success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetSellerInfoByMobile_004() {
		Logger.start(true,"不输入区号失败"); 
		try {
			getsellerinfobymobileBean.setMobile(TestDataManager.getPhoneNum());
//			getsellerinfobymobileBean.setMobileAreaCode("1");
			getsellerinfobymobileCall.setData(getsellerinfobymobileBean);
			getsellerinfobymobileCall.callService();			
			Logger.verifyEquals("false", getsellerinfobymobileCall.getString("success"), "验证success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSellerInfoByMobile_005() {
		Logger.start(true,"用户不是商家失败");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			u.setMobile(TestDataManager.getPhoneNum());
			u.setMobileAreaCode("86");
			int user = DGUserCallService.UserCreateCall(u);
			getsellerinfobymobileBean.setMobile(u.getMobile());
			getsellerinfobymobileBean.setMobileAreaCode(u.getMobileAreaCode());
			getsellerinfobymobileCall.setData(getsellerinfobymobileBean);
			getsellerinfobymobileCall.callService();			
			Logger.verifyEquals("true", getsellerinfobymobileCall.getString("success"), "验证success");
			Logger.verifyIsNull(getsellerinfobymobileCall.getJsonObject().get("sellerDto"), "验证没数据");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSellerInfoByMobile_006() {
		Logger.start(true,"根据手机号码查询商家信息成功-手机号注册不绑定微信");
		try {
			UserCreateBean u = DGUserCallService.initSellerUsercreateBean();
			u.setOpenId(null);
			u.setUnionId(null);
			int user = DGUserCallService.UserCreateCall(u);
			getsellerinfobymobileBean.setMobile(u.getMobile());
			getsellerinfobymobileBean.setMobileAreaCode(u.getMobileAreaCode());
			getsellerinfobymobileCall.setData(getsellerinfobymobileBean);
			getsellerinfobymobileCall.callService();			
			Logger.verifyEquals("true", getsellerinfobymobileCall.getString("success"), "验证success");
			Logger.verifyEquals(user, getsellerinfobymobileCall.getJsonObject().get("sellerDto").getAsJsonObject().get("userId").getAsInt(), "验证userId");
			//userStauts 0 正常
			Logger.verifyEquals(0, getsellerinfobymobileCall.getJsonObject().get("sellerDto").getAsJsonObject().get("userStauts").getAsInt(), "验证userStauts");
			Logger.verifyEquals(false, getsellerinfobymobileCall.getJsonObject().get("bindWx").getAsBoolean(), "验证bindWx");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSellerInfoByMobile_007() {
		Logger.start(true,"商家手机号在这个wxapp内存在");
		try { 
			CreateUserBackBean usercreateBean= DGUserCallService.initUsercreateNewBean();
			usercreateBean.setUserType(1);
			Integer userid = DGUserCallService.UserCreateNewCall(usercreateBean);
			DGUserCallService.ReceiveUserCreateNewCall(userid);
			getsellerinfobymobileBean.setMobile(usercreateBean.getMobile());
			getsellerinfobymobileBean.setMobileAreaCode(usercreateBean.getMobileAreaCode());
			getsellerinfobymobileBean.setWxAppName(userid+"");
			getsellerinfobymobileCall.setData(getsellerinfobymobileBean);
			getsellerinfobymobileCall.callService();			
			
			Logger.verifyEquals("true", getsellerinfobymobileCall.getString("success"), "验证success");
			Logger.verifyEquals(userid, getsellerinfobymobileCall.getJsonObject().get("sellerDto").getAsJsonObject().get("userId").getAsInt(), "验证userId");
			//userStauts 0 正常
			Logger.verifyEquals(0, getsellerinfobymobileCall.getJsonObject().get("sellerDto").getAsJsonObject().get("userStauts").getAsInt(), "验证userStauts");
			Logger.verifyEquals(false, getsellerinfobymobileCall.getJsonObject().get("bindWx").getAsBoolean(), "验证bindWx");
		} catch (Throwable e) {
			Logger.fail(new Exception(e));
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSellerInfoByMobile_008() {
		Logger.start(true,"手机号在这个wxapp内存在，不过是用户手机号，不存在");
		try {
			CreateUserBackBean usercreateBean= DGUserCallService.initUsercreateNewBean();
			Integer userid = DGUserCallService.UserCreateNewCall(usercreateBean);
			getsellerinfobymobileBean.setMobile(usercreateBean.getMobile());
			getsellerinfobymobileBean.setMobileAreaCode(usercreateBean.getMobileAreaCode());
			getsellerinfobymobileBean.setWxAppName(userid+"");
			getsellerinfobymobileCall.setData(getsellerinfobymobileBean);
			getsellerinfobymobileCall.callService();			
			Logger.verifyEquals("true", getsellerinfobymobileCall.getString("success"), "验证success");
			Logger.verifyEquals(false, getsellerinfobymobileCall.getJsonObject().get("bindWx").getAsBoolean(), "验证bindWx");
		} catch (Throwable e) {
			Logger.fail(new Exception(e));
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSellerInfoByMobile_009() {
		Logger.start(true,"根据手机号码查询商家信息成功-查询分销员");
		try {
			UserCreateBean u = DGUserCallService.initSellerUsercreateBean();
			u.setUserType(3);
			int user = DGUserCallService.UserCreateCall(u);
			getsellerinfobymobileBean.setMobile(u.getMobile());
			getsellerinfobymobileBean.setMobileAreaCode(u.getMobileAreaCode());
			getsellerinfobymobileCall.setData(getsellerinfobymobileBean);
			getsellerinfobymobileCall.callService();			
			Logger.verifyEquals("true", getsellerinfobymobileCall.getString("success"), "验证success");
			Logger.verifyEquals(user, getsellerinfobymobileCall.getJsonObject().get("sellerDto").getAsJsonObject().get("userId").getAsInt(), "验证userId");
			//userStauts 0 正常
			Logger.verifyEquals(0, getsellerinfobymobileCall.getJsonObject().get("sellerDto").getAsJsonObject().get("userStauts").getAsInt(), "验证userStauts");
			Logger.verifyEquals(true, getsellerinfobymobileCall.getJsonObject().get("bindWx").getAsBoolean(), "验证bindWx");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSellerInfoByMobile_010() {
		Logger.start(true,"查询不同店铺里相同手机号的分销员");
		try {
			UserCreateBean u = DGUserCallService.initSellerUsercreateBean();
			u.setUserType(3);
			int user = DGUserCallService.UserCreateCall(u);
			
			UserCreateBean u2 = DGUserCallService.initSellerUsercreateBean();
			u2.setUserType(3);
			u2.setWxAppName(DGUserCallService.TestWxsqOtherSellerId.toString());
			int user2 = DGUserCallService.UserCreateCall(u2);
			
			
			getsellerinfobymobileBean.setMobile(u.getMobile());
			getsellerinfobymobileBean.setMobileAreaCode(u.getMobileAreaCode());
			getsellerinfobymobileBean.setWxAppName(u.getWxAppName());
			getsellerinfobymobileCall.setData(getsellerinfobymobileBean);
			getsellerinfobymobileCall.callService();			
			Logger.verifyEquals("true", getsellerinfobymobileCall.getString("success"), "验证success");
			Logger.verifyEquals(user, getsellerinfobymobileCall.getJsonObject().get("sellerDto").getAsJsonObject().get("userId").getAsInt(), "验证userId");
			getsellerinfobymobileBean.setMobile(u2.getMobile());
			getsellerinfobymobileBean.setMobileAreaCode(u2.getMobileAreaCode());
			getsellerinfobymobileBean.setWxAppName(u2.getWxAppName());
			getsellerinfobymobileCall.setData(getsellerinfobymobileBean);
			getsellerinfobymobileCall.callService();			
			Logger.verifyEquals("true", getsellerinfobymobileCall.getString("success"), "验证success");
			Logger.verifyEquals(user2, getsellerinfobymobileCall.getJsonObject().get("sellerDto").getAsJsonObject().get("userId").getAsInt(), "验证userId");
			
		} catch (Throwable e) {
			Logger.fail(new Exception(e));
		}
	}
	
}